{% extends 'base_children.html' %}
{% block self_head %}

 <link  rel="stylesheet" href="/static/larryms/thirdlib/formSelects-v4.css" >
<script src="/static/larryms/plus/ace-1.4.2/src-min-noconflict/ace.js"></script>
    <script src="/static/larryms/plus/ace-1.4.2/src-min-noconflict/ext-language_tools.js"></script>
{#   <script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.1/mode-mysql.js"></script>#}
    <script src="/static/larryms/plus/ace-1.4.2/src-min-noconflict/mode-python.js"></script>
    <script src="/static/larryms/plus/ace-1.4.2/src-min-noconflict/mode-sql.js"></script>
    <script src="/static/larryms/plus/ace-1.4.2/src-min-noconflict/mode-yaml.js"></script>
    <script src="/static/larryms/plus/ace-1.4.2/src-min-noconflict/mode-sh.js"></script>
{#    <script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.1/snippets/sh.js"></script>#}
{#    <script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.1/snippets/sql.js"></script>#}
{#    <script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.1/snippets/yaml.js"></script>#}


    <script src="/static/larryms/plus/ace-1.4.2/src-min-noconflict/theme-monokai.js"></script>

{#    <script src="/static/larryms/plus/ace-1.4.2/src-min/theme-terminal.js"></script>#}
{#<script src="http://cdn.bootcss.com/ace/1.2.4/ace.js"></script>#}
{#<script src="http://cdn.bootcss.com/ace/1.2.4/ext-language_tools.js"></script>#}
{#<script src="http://cdn.bootcss.com/ace/1.2.4/ext-old_ie.js"></script>#}
{#<script src="http://cdn.bootcss.com/ace/1.2.4/theme-monokai.js"></script> #}

<style type="text/css">
	#editor {
		/* position: absolute; */
	width: 100%;
	height: 400px;

   }	
</style>
{% endblock %}
{% block content %}
<div class="layui-fluid form-demo-box">
    <div class="layui-row">
         <div class="layui-col-lg6">
             <section>
                 <div class="layui-card">
                     <div class="layui-card-header">
                           <strong>执行脚本文件</strong>
                     </div>
                     <div class="layui-card-body" style="height: 900px;">
                         <form class="layui-form layui-form-pane" id="ansiblescriptRun" lay-filter="layui-form" action="{% url 'ansible_exe_script' %}">
                                      {% csrf_token %}

                                         <div class="layui-form-item">
                                            <label class="layui-form-label">脚本名称</label>
                                             <div class="layui-input-block">
                                                 <input  name="script_name" class="layui-input" value="fast_script_{{ time_now }}" required>
                                             </div>
                                        </div>

                                    <div class="layui-form-item">
                                        <label class="layui-form-label">产品线</label>
                                        <div class="layui-input-block">
                                            <select name="prod_line" xm-select='prod_line'  xm-select-radio>
                                                    <option value="">先选择业务线的host，再选择机器</option>
                                            </select>
{#                                             <input type="text" id="yewuxian" class="layu=3i-input" readonly="readonly">#}
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">目标机器</label>
                                        <div class="layui-input-block">
                                            <select name='hosts' id="select_host" xm-select='select_host'  xm-select-max="3">
                                                    <option value="">选择业务线后,选择一个或多个服务器</option>
                                            </select>

                                        </div>
                                    </div>



{#                                    //这里可以调用ansble de 执行uuid#}
                                    <input  type="hidden"  id="ans_uuid" name="ans_uuid" value="{{ans_uuid}}">
										<div class="layui-form-item" >

											<div class="layui-btn-container">
												<button type="button" class="layui-btn layui-btn-normal  layui-btn-sm"  layui-submit="" lay-filter='edit_sh' id="edit_sh">Shell</button>
                                                <button type="button" class="layui-btn layui-btn-normal layui-btn-sm"  layui-submit="" lay-filter='edit_python' id="edit_python">python</button>
                                                <button type="button" class="layui-btn layui-btn-normal  layui-btn-sm"  layui-submit="" lay-filter='edit_perl' id="edit_perl" >perl</button>

											</div>
										</div>

                              <div id="editor" ></div>


                                        <div class="layui-form-item">
                                            <label class="layui-form-label">脚本参数</label>
                                            <div class="layui-input-block">
                                                <input class="layui-input" name="script_args" id="script_args"   placeholder="多个参数以空格分开">
                                            </div>

                                        </div>

                             <div class="layui-form-item">
                                        <label class="layui-form-label">调试模式</label>
                                        <div class="layui-input-block">
                                            <input type="checkbox" name="ans_debug" lay-skin="switch" value="ON"  lay-text="ON|OFF">
                                        </div>
                                    </div>



                             <button type="button" class="layui-btn layui-btn-warm" lay-submit="" lay-filter='save_script' id="save_script">保存</button>
                             <button type="button" class="layui-btn layui-btn-green" lay-submit="" lay-filter='runjob' id="run_ansible_model">运行</button>


                         </form>

                     </div>
                 </div>
             </section>

         </div>

        <div class="layui-col-lg6">
            <section>
                     <div class="layui-card">
                            <div class="layui-card-header">

                                <strong>执行结果</strong>

                            </div>
                            <div class="layui-card-body">

                                <div class="html">
                                    <div id="result">
                                    </div>
                                </div>
                            </div>

                        </div>
            </section>
        </div>

    </div>

</div>




{% endblock %}
{% block self_foot %}
    <script type="text/javascript">



function setAceEditMode(model) {
	var editor = ace.edit("editor");

	var langTools = ace.require("ace/ext/language_tools");

	editor.removeLines();
	editor.setTheme("ace/theme/monokai");
	if (model == 'sh'){
	    editor.removeLines()
		editor.insert("#!/bin/bash");
		editor.insert("\n");
	}
	else if(model == 'python'){
	     editor.removeLines()
		editor.insert("#!/usr/bin/python");
			editor.insert("\n");
	}
	else if(model == 'perl'){
	     editor.removeLines()
		editor.insert("#!/usr/bin/perl");
			editor.insert("\n");
	}
	else{
		editor.insert("#!/bin/bash");
		var model = 'sh'
	};
	editor.getSession().setMode("ace/mode/" + model);
	editor.setShowPrintMargin(false);
	editor.setOptions({
	    enableBasicAutocompletion: true,
	    enableSnippets: true,
	    enableLiveAutocompletion: true
	});

};




{##}
{#function oBtProjectSelect(){#}
{#	   $('#ansible_service').removeAttr("disabled");#}
{#	   var obj = document.getElementById("ansible_project"); #}
{#	   var index = obj.selectedIndex;#}
{#	   var projectId = obj.options[index].value; #}
{#	   if ( projectId > 0){	 #}
{#			$.ajax({#}
{#				dataType: "JSON",#}
{#				url:'/api/project/'+ projectId + '/', //请求地址#}
{#				type:"GET",  //提交类似#}
{#				success:function(response){#}
{#					var binlogHtml = '<select class="form-control" name="ansible_service" id="ansible_service" onchange="javascript:oBtServiceSelect();" required><option selected="selected" name="ansible_service" value="">请选择业务类型</option>'#}
{#					var selectHtml = '';#}
{#					for (var i=0; i <response["service_assets"].length; i++){#}
{#						 selectHtml += '<option name="ansible_service" value="'+ response["service_assets"][i]["id"] +'">' + response["service_assets"][i]["service_name"] + '</option>' #}
{#					};                        #}
{#					binlogHtml =  binlogHtml + selectHtml + '</select>';#}
{#					document.getElementById("ansible_service").innerHTML= binlogHtml;	#}
{#						#}
{#				},#}
{#			});	#}
{#	   }#}
{#	   else{#}
{#		   $('#ansible_service').attr("disabled",true);#}
{#	   }#}
{##}
{# }#}

{#function oBtServiceSelect(model,ids){#}
{#	   var obj = document.getElementById(ids); #}
{#	   var index = obj.selectedIndex;#}
{#	   var sId = obj.options[index].value; #}
{#	   if ( sId  > 0){	 #}
{#			$.ajax({#}
{#				dataType: "JSON",#}
{#				url:'/assets_server/', //请求地址#}
{#				type:"POST",  //提交类似#}
{#				data:{#}
{#					"query":model,#}
{#					"id":sId#}
{#				},#}
{#				success:function(response){#}
{#					var sHtml = '';#}
{#					for (var i=0; i <response["data"].length; i++){#}
{#						sHtml += '<br>' + response["data"][i]["ip"] + " | " + response["data"][i]["project"] + " | " + response["data"][i]["service"]#}
{#					};  #}
{#					if ( sHtml.length > 0){#}
{#						$.notify({#}
{#							title: "<strong>发现主机:</strong>",#}
{#							message: sHtml#}
{#						},#}
{#						{#}
{#							type: 'info'#}
{#						});	#}
{#						$('#run_ansible_model').removeAttr("disabled");#}
{#					}#}
{#					else {#}
{#						$.notify({#}
{#							title: "<strong>Ops：</strong>",#}
{#							message: "该条件下未发现主机资源~"#}
{#						},#}
{#						{#}
{#							type: 'danger'#}
{#						});#}
{#						$('#run_ansible_model').attr("disabled",true);#}
{#					}#}
{#				#}
{#						#}
{#				},#}
{#			});	#}
{#	   }#}
{#	   else{#}
{#		   $('#server option:selected').empty();#}
{#		   $('#server').attr("disabled",true);#}
{#	   }#}
{##}
{# }	#}

{##}
{#	function runAnsibleModel(obj) {#}
{#		var btnObj = $(obj);#}
{#		btnObj.attr('disabled',true);#}
{#		var form = document.getElementById('ansibleModelRun');#}
{#		var editor = ace.edit("compile-editor");#}
{#	    var contents = editor.getSession().getValue(); #}
{#	    if ( contents.length == 0){#}
{#	    	window.wxc.xcConfirm("脚本内容不能为空", window.wxc.xcConfirm.typeEnum.error);#}
{#	    	btnObj.removeAttr('disabled');#}
{#	    	return false;#}
{#	    };		#}
{#		$("#result").html("服务器正在处理，请稍等。。。");#}
{#		var ansible_server = new Array();#}
{#		$("#ansible_server option:selected").each(function(){#}
{#			ansible_server.push($(this).val());#}
{#        });#}
{#		/* 轮训获取结果 开始  */#}
{# 	   var interval = setInterval(function(){  #}
{#	        $.ajax({  #}
{#	            url : '/apps/run/',  #}
{#	            type : 'post', #}
{#	            data:$('#ansibleModelRun').serialize(),#}
{#	            success : function(result){#}
{#	            	if (result["msg"] !== null ){#}
{#	            		$("#result").append("<p>"+result["msg"]+"</p>"); #}
{#	            		document.getElementById("scrollToTop").scrollIntoView(); #}
{#	            		if (result["msg"].indexOf("[Done]") == 0){#}
{#	            			clearInterval(interval);#}
{#	            			window.wxc.xcConfirm("Ansible执行完成", window.wxc.xcConfirm.typeEnum.success);#}
{#	            			btnObj.removeAttr('disabled');#}
{#	            		}#}
{#	            	}#}
{#	            },#}
{#		    	error:function(response){#}
{#		    		btnObj.removeAttr('disabled');#}
{#		    		clearInterval(interval);#}
{#		    	}	            #}
{#	        });  #}
{#	    },1000);  #}
{#// 	    /* 轮训获取结果结束  */#}
{#		$.ajax({#}
{#			url:'/apps/script/online/', //请求地址#}
{#			type:"POST",  //提交类似#}
{#			data:{#}
{#				'type':'run',#}
{#				'script_name':document.getElementById("script_name").value,#}
{#				'server_model':$('#server_model option:selected').val(),#}
{#				'script_args':document.getElementById("script_args").value,#}
{#				'ansible_service':$('#ansible_service option:selected').val(),#}
{#				'ansible_group':$('#script_auth_group option:selected').val(),#}
{#				'model':document.getElementById("model").value,#}
{#				'ans_uuid':document.getElementById("ans_uuid").value,#}
{#				'script_file':contents,#}
{#				'ansible_debug':document.getElementById("ansible_debug").value,#}
{#				'ansible_server':ansible_server#}
{#			},//$('#ansibleModelRun').serialize() + '&script_file=' + contents,  //不能是被脚本里面的&&符号#}
{#			success:function(response){#}
{#				btnObj.removeAttr('disabled');#}
{#				if (response["code"] == "500"){#}
{#					clearInterval(interval);#}
{#					btnObj.removeAttr('disabled');#}
{#					window.wxc.xcConfirm(response["msg"], window.wxc.xcConfirm.typeEnum.error);#}
{#				}#}
{#				#}
{#			},#}
{#	    	error:function(response){#}
{#	    		btnObj.removeAttr('disabled');#}
{#	    		window.wxc.xcConfirm("运行失败", window.wxc.xcConfirm.typeEnum.error);#}
{#	    		clearInterval(interval);#}
{#	    	}#}
{#		})	#}
{#	}	#}

{#	function saveAnsibleScript(obj){#}
{#		var btnObj = $(obj);#}
{#		btnObj.attr('disabled',true);#}
{#		var form = document.getElementById('ansibleModelRun');#}
{#		var editor = ace.edit("compile-editor");#}
{#	    var contents = editor.getSession().getValue(); #}
{#	    var script_name = document.getElementById("script_name").value;#}
{#	    if ( contents.length == 0 || script_name.length == 0){#}
{#	    	window.wxc.xcConfirm("脚本内容与名称不能为空", window.wxc.xcConfirm.typeEnum.error);#}
{#	    	btnObj.removeAttr('disabled');#}
{#	    	return false;#}
{#	    };		#}
{#		var ansible_server = new Array();#}
{#		$("#ansible_server option:selected").each(function(){#}
{#			ansible_server.push($(this).val());#}
{#        });#}
{#// 	    /* 轮训获取结果结束  */#}
{#		$.ajax({#}
{#			url:'/apps/script/online/', //请求地址#}
{#			type:"POST",  //提交类似#}
{#			data:{#}
{#				'type':'save',#}
{#				'script_name':document.getElementById("script_name").value,#}
{#				'server_model':$('#server_model option:selected').val(),#}
{#				'ansible_service':$('#ansible_service option:selected').val(),#}
{#				'ansible_group':$('#script_auth_group option:selected').val(),#}
{#				'script_args':document.getElementById("script_args").value,#}
{#				'model':document.getElementById("model").value,#}
{#				'ans_uuid':document.getElementById("ans_uuid").value,#}
{#				'script_file':contents,#}
{#				'ansible_debug':document.getElementById("ansible_debug").value,#}
{#				'ansible_server':ansible_server#}
{#			},//$('#ansibleModelRun').serialize() + '&script_file=' + contents,  //不能是被脚本里面的&&符号#}
{#			success:function(response){#}
{#				btnObj.removeAttr('disabled');#}
{#				if (response["code"] == "500"){#}
{#					window.wxc.xcConfirm(response["msg"], window.wxc.xcConfirm.typeEnum.error);#}
{#				}#}
{#				else{#}
{#					window.wxc.xcConfirm(response["msg"], window.wxc.xcConfirm.typeEnum.success);					#}
{#				}#}
{#				#}
{#			},#}
{#	    	error:function(response){#}
{#	    		btnObj.removeAttr('disabled');#}
{#	    		window.wxc.xcConfirm("运行失败", window.wxc.xcConfirm.typeEnum.error);#}
{#	    	}#}
{#		})			#}
{#	}#}
{#editor.getSession().setMode("ace/mode/sh");#}
    setAceEditMode("sh");
</script>
    <script type="text/javascript">
        layui.config({
            version: "2.0.8",
            base: '/static/larryms/',
            layertype:2
        }).extend({
            larry: 'js/base'
        }).use(['larry', 'layer', 'jquery', 'larryms', 'form','formSelects'], function () {
            var $ = layui.$,
                larry = layui.larry,
                form = layui.form,
                layer = layui.layer,
                formSelects = layui.formSelects,
                larryms = layui.larryms;

            {#var curIfr = parent.layer.getFrameIndex(window.name);#}
$('#edit_sh').on('click',function(){

      setAceEditMode("sh");
   });

 $('#edit_python').on('click',function () {
         setAceEditMode("python");
 });
 $('#edit_perl').on('click',function () {
         setAceEditMode("perl");
 });


            form.on('submit(runjob)', function (data) {
                console.log(data.field)
                var btnObj = $(data);
                btnObj.attr('disabled', true);
	        var editor = ace.edit("editor");
	    var contents = editor.getSession().getValue();
	    if ( contents.length == 0){
	        larryms.msg("脚本内容不能为空");
	    	btnObj.removeAttr('disabled');
	    	return false;
	    };

                $("#result").html("服务器正在处理，请稍等。。。");
                /* 轮训获取结果 开始  */
                var interval = setInterval(function () {
                    $.ajax({
                        url: '{% url 'get_ans_run_result' %}',
                        type: 'post',
                        data: data.field,
                        success: function (result) {
                            if (result["msg"] !== null) {
                                $("#result").append("<p>" + result["msg"] + "</p>");
                                {#document.getElementById("scrollToTop").scrollIntoView();#}
                                if (result["msg"].indexOf("[Done]") == 0) {
                                    clearInterval(interval);
                                    larryms.msg("Ansible执行完成");
                                    btnObj.removeAttr('disabled');
                                }
                            }
                        },
                        error: function (response) {
                            btnObj.removeAttr('disabled');
                            clearInterval(interval);
                        }
                    });
                }, 10);  //一秒钟运行2此

// 	    /* 轮训获取结果结束  */
                $.ajax({
                    dataType: "text",
                    url: '{% url 'ansible_exe_script' %}', //请求地址
                    type: "POST",  //提交类似
                      {#contentType: "application/json",#}
                    data: {
                        "script_content":contents ,
                    "ans_uuid":data.field.ans_uuid ,
            "csrfmiddlewaretoken": data.field.csrfmiddlewaretoken,
"hosts":data.field.hosts ,
"script_args": data.field.script_args,
"script_name": data.field.script_name
                    },  //提交参数
                    success: function (res) {
                        btnObj.removeAttr('disabled');
                        if (res["code"] == "500") {
                            clearInterval(interval);
                            btnObj.removeAttr('disabled');
                            larryms.msg(res["msg"]);
                        }

                    },
                    error: function (response) {
                        btnObj.removeAttr('disabled');
                        larryms.msg("运行失败" );
                        clearInterval(interval);
                    }
                });


            });


            formSelects.config('prod_line', {
    type: 'get',                //ÇëÇó·½Ê½: post, get, put, delete...
    header: {},                 //×Ô¶¨ÒåÇëÇóÍ·
    data: {},                   //×Ô¶¨Òå³ýËÑË÷ÄÚÈÝÍâµÄÆäËûÊý¾Ý
    searchUrl: '{% url 'get_json_tree' %}',
    searchName: 'keyword',      //×Ô¶¨ÒåËÑË÷ÄÚÈÝµÄkeyÖµ
    searchVal: '',              //×Ô¶¨ÒåËÑË÷ÄÚÈÝ, ËÑËØÒ»´ÎºóÊ§Ð§, ÓÅÏÈ¼¶¸ßÓÚËÑË÷¿òÖÐµÄÖµ
    keyName: 'name',            //×Ô¶¨Òå·µ»ØÊý¾ÝÖÐnameµÄkey, Ä¬ÈÏ name
    keyVal: 'value',            //×Ô¶¨Òå·µ»ØÊý¾ÝÖÐvalueµÄkey, Ä¬ÈÏ value
    keySel: 'selected',         //×Ô¶¨Òå·µ»ØÊý¾ÝÖÐselectedµÄkey, Ä¬ÈÏ selected
    keyDis: 'disabled',         //×Ô¶¨Òå·µ»ØÊý¾ÝÖÐdisabledµÄkey, Ä¬ÈÏ disabled
    keyChildren: 'children',    //Áª¶¯¶àÑ¡×Ô¶¨Òåchildren
    delay: 500,                 //ËÑË÷ÑÓ³ÙÊ±¼ä, Ä¬ÈÏÍ£Ö¹ÊäÈë500msºó¿ªÊ¼ËÑË÷
    direction: 'auto',          //¶àÑ¡ÏÂÀ­·½Ïò, auto|up|down
    response: {
        statusCode: 0,          //³É¹¦×´Ì¬Âë
        statusName: 'code',     //code key
        msgName: 'msg',         //msg key
        dataName: 'data'        //data key
    },
    success: function(id, url, searchVal, result){      //Ê¹ÓÃÔ¶³Ì·½Ê½µÄsuccess»Øµ÷
        console.log(id);        //×é¼þID xm-select
        console.log(url);       //URL
        console.log(searchVal); //ËÑË÷µÄvalue
        console.log(result);    //·µ»ØµÄ½á¹û
    },
    error: function(id, url, searchVal, err){           //Ê¹ÓÃÔ¶³Ì·½Ê½µÄerror»Øµ÷
        //
        console.log(err);   //err¶ÔÏó
    },
    beforeSuccess: function(id, url, searchVal, result){

        result.data=JSON.parse(result.data)
        return result;  //±ØÐëreturnÒ»¸ö½á¹û, Õâ¸ö½á¹ûÒª·ûºÏ¶ÔÓ¦µÄÊý¾Ý½á¹¹
    },
    beforeSearch: function(id, url, searchVal){         //ËÑË÷Ç°µ÷ÓÃ´Ë·½·¨, return true½«´¥·¢ËÑË÷, ·ñÔò²»´¥·¢
        if(!searchVal){//Èç¹ûËÑË÷ÄÚÈÝÎª¿Õ,¾Í²»´¥·¢ËÑË÷
            return false;
        }
        return true;
    },
    clearInput: false,          //µ±ÓÐËÑË÷ÄÚÈÝÊ±,  µã»÷Ñ¡ÏîÊÇ·ñÇå¿ÕËÑË÷ÄÚÈÝ, Ä¬ÈÏ²»Çå¿Õ
   }, true);
            formSelects.data('prod_line','server',{
                url: '{% url 'get_json_tree' %}',

                 linkage: true,
                linkageWidth:130,
                 keyChildren: 'children',
                keyName: 'name',
                keyVal: 'value',
                 success: function(result){
						        console.log(result);
						    },
                 error: function(err){           //Ê¹ÓÃÔ¶³Ì·½Ê½µÄerror»Øµ÷
						        //Í¬ÉÏ
						        console.log(err);   //err¶ÔÏó
						    },


            });

          formSelects.on('prod_line', function(id, vals, val, isAdd, isDisabled){
              var hostids='';
              for(var i in vals)
              {
                  var  hostname=vals[i].name.split('/').pop();
                  var hostid=vals[i].value.split('/').pop();
                  if (hostname ==='host')
                  {
	   $('#select_host option:selected').empty();

		   if ( hostid > 0){

  formSelects.config('select_host', {
    type: 'get',                //ÇëÇó·½Ê½: post, get, put, delete...
    header: {},                 //×Ô¶¨ÒåÇëÇóÍ·
    data: {},                   //×Ô¶¨Òå³ýËÑË÷ÄÚÈÝÍâµÄÆäËûÊý¾Ý
    searchUrl: '',           //ËÑË÷µØÖ·, Ä¬ÈÏÊ¹ÓÃxm-select-searchµÄÖµ, ´Ë²ÎÊýÓÅÏÈ¼¶¸ß
    searchName: 'keyword',      //×Ô¶¨ÒåËÑË÷ÄÚÈÝµÄkeyÖµ
    searchVal: '',              //×Ô¶¨ÒåËÑË÷ÄÚÈÝ, ËÑËØÒ»´ÎºóÊ§Ð§, ÓÅÏÈ¼¶¸ßÓÚËÑË÷¿òÖÐµÄÖµ
    keyName: 'name',            //×Ô¶¨Òå·µ»ØÊý¾ÝÖÐnameµÄkey, Ä¬ÈÏ name
    keyVal: 'value',            //×Ô¶¨Òå·µ»ØÊý¾ÝÖÐvalueµÄkey, Ä¬ÈÏ value
    keySel: 'selected',         //×Ô¶¨Òå·µ»ØÊý¾ÝÖÐselectedµÄkey, Ä¬ÈÏ selected
    keyDis: 'disabled',         //×Ô¶¨Òå·µ»ØÊý¾ÝÖÐdisabledµÄkey, Ä¬ÈÏ disabled

    delay: 500,                 //ËÑË÷ÑÓ³ÙÊ±¼ä, Ä¬ÈÏÍ£Ö¹ÊäÈë500msºó¿ªÊ¼ËÑË÷
    direction: 'auto',          //¶àÑ¡ÏÂÀ­·½Ïò, auto|up|down
    response: {
        statusCode: 0,          //³É¹¦×´Ì¬Âë
        statusName: 'code',     //code key
        msgName: 'msg',         //msg key
        dataName: 'data'        //data key
    },
    success: function(id, url, searchVal, result){      //Ê¹ÓÃÔ¶³Ì·½Ê½µÄsuccess»Øµ÷
        console.log(id);        //×é¼þID xm-select
        console.log(url);       //URL
        console.log(searchVal); //ËÑË÷µÄvalue
        console.log(result);    //·µ»ØµÄ½á¹û
    },
    error: function(id, url, searchVal, err){           //Ê¹ÓÃÔ¶³Ì·½Ê½µÄerror»Øµ÷
        //
        console.log(err);   //err¶ÔÏó
    },
    beforeSuccess: function(id, url, searchVal, result){

        result.data=JSON.parse(result.data)
        return result;  //±ØÐëreturnÒ»¸ö½á¹û, Õâ¸ö½á¹ûÒª·ûºÏ¶ÔÓ¦µÄÊý¾Ý½á¹¹
    },
    beforeSearch: function(id, url, searchVal){         //ËÑË÷Ç°µ÷ÓÃ´Ë·½·¨, return true½«´¥·¢ËÑË÷, ·ñÔò²»´¥·¢
        if(!searchVal){//Èç¹ûËÑË÷ÄÚÈÝÎª¿Õ,¾Í²»´¥·¢ËÑË÷
            return false;
        }
        return true;
    },
    clearInput: false,          //µ±ÓÐËÑË÷ÄÚÈÝÊ±, µã»÷Ñ¡ÏîÊÇ·ñÇå¿ÕËÑË÷ÄÚÈÝ, Ä¬ÈÏ²»Çå¿Õ
}, true);
				formSelects.data('select_host', 'server', {
    url: '/cmdb/get_json_tree_host/'+ hostid ,

});
		   };

                  }
                  else{
                      larryms.alert('最后的节点要是host，才能选出主机奥');
                      formSelects.value('prod_line',[vals[i].value],false) ;//删掉这个值
                  }
                  console.log(hostname);
                  console.log(hostid)

              };
        }, true);


        });


    </script>
{%endblock %}